/**
 * 输入框获取焦点，提示信息列背影样式修改为labbg_normal，提示文本内容显示
 * @param tdId 提示信息列ID
 * @param spanId 提示文本内容描述对象ID
 */
function chgPwdInputOnFocusListener(tdId, spanId) {
    var tdObj = document.getElementById(tdId);
    if(tdObj) {
        tdObj.className = "labbg_normal";
    }
    
    var spanObj = document.getElementById(spanId);
    if(spanObj) {
        spanObj.style.display = "block";
        spanObj.innerHTML = "密码由6-16位半角字符(字母、数字、符号)组成，区分大小写";
    }
}

String.prototype.trim = function(){
    return this.replace(/(^[\s]*)|([\s]*$)/g, "");
};

/**
 * 密码输入框失去焦点，提示信息列背影样式修改，提示文本内容修改
 * 同时对输入的密码进行校验，如果校验有误则显示错误提示信息
 * 
 * @param inputObj 输入对象
 * @param tdId 信息提示列ID
 * @param descSpanId 描述信息Span ID
 * @param errInfoSpanId 错误提示信息Span ID
 */
function lostFocusInputListener(inputObj, tdId, descSpanId) {
	var result = false;
	
    var inputValue = inputObj.value;
    if(inputValue != "") {
    	inputValue = inputValue.trim();
    	inputObj.value = inputValue;
    }
    
    var tdIdObj = document.getElementById(tdId);
    var descSpanidObj = document.getElementById(descSpanId);
    
    descSpanidObj.style.display = "none";
    
    var chkRsObj = chkPwd(inputValue);
    
    // 校验有误
    if(!chkRsObj.result) {
    	tdIdObj.className = "labbg_err";
    	descSpanidObj.style.display = "block";
    	descSpanidObj.innerHTML = chkRsObj['info'];
    } else {
    	// 校验通过
    	tdIdObj.className = "";
    	descSpanidObj.style.display = "none";
    	descSpanidObj.innerHTML = "";
    	
    	result = true;
    }
    
    return result;
}

/**
 * 密码确认输入框
 * 
 * @param inputObj 输入对象
 * @param tdId 信息提示列ID
 * @param newPwdId 第一个密码输入框
 * @param descSpanId 描述信息Span ID
 * @param errInfoSpanId 错误提示信息Span ID
 */
function lostFocusConfirmInputListener(inputObj, tdId, newPwdId, descSpanId) {
	var chRs = lostFocusInputListener(inputObj, tdId, descSpanId);
	if(chRs) {
		// 判断两次密码是否相等
		var secPwd = inputObj.value;
		var newPwdIdObj = document.getElementById(newPwdId);
		var firPwd = newPwdIdObj.value.trim();
		newPwdIdObj.value = firPwd;
		
		var tdIdObj = document.getElementById(tdId);
		var descSpanIdObj = document.getElementById(descSpanId);
		if(secPwd != firPwd) {
			tdIdObj.className = "labbg_err";
			descSpanIdObj.style.display = "block";
			descSpanIdObj.innerHTML = "两次输入的密码不一致，请重新输入";
		} else {
	    	// 校验通过
	    	tdIdObj.className = "";
	    	descSpanidObj.style.display = "none";
	    	descSpanidObj.innerHTML = "";
	    }
	}
}

/**
 * 密码校验 
 * @param passwordValue
 * @returns {___resultObj0}
 */
function chkPwd(passwordValue) {
	var resultObj = new Object();
	resultObj['result'] = false;
	
	// 密码不能为空
	if(passwordValue == "" || passwordValue.length < 6 || passwordValue.length > 16) {
		resultObj['info'] = "密码长度不正确，应为6~16个字符 ";
		return resultObj;
	}
	
	resultObj.result = true;
	return resultObj;
}

/**
 * 提交时表单校验
 */
function infoModifyFormFun() {
	// 原密码校验
    var oldPwdChkRs = privatePwdItemChk("oldPwd", "oldPwdCol", "oldpwddesc");
    if(!oldPwdChkRs) {
    	return false;
    }
	
    // 新密码校验
    var newPwdChkRs = privatePwdItemChk("newPwd", "newPwdCol", "newpwddesc");
    if(!newPwdChkRs) {
    	return false;
    }
    
    if(!equalscheck("oldPwd", "newPwd", "当前密码", "新密码", "newPwdCol", "newpwddesc")) {
    	return false;
    }
	
    // 新密码确认
    var newPwdChkRs2 = privatePwdItemChk("newPwd2", "newPwdCol2", "newpwddesc2");
    if(!newPwdChkRs2) {
    	return false;
    }
    
    if(!equalscheck("oldPwd", "newPwd2", "当前密码", "新密码确认", "newPwdCol2", "newpwddesc2")) {
    	return false;
    }
    
    // 新密码不能与原密码相同
    if(!equalscheck2("newPwd", "newPwd2", "newPwdCol2", "newpwddesc2")) {
    	return false;
    }
    
    document.getElementById("infoModifyForm").submit();
    return true;
}

/**
 * 表单提交时校验使用
 * @param inputId
 * @param tdId
 * @param spanId
 */
function privatePwdItemChk(inputId, tdId, spanId) {
	var pwdObj = document.getElementById(inputId); // 表单输入项
	var pwdObjValue = pwdObj.value;
    if(pwdObjValue != "") {
    	pwdObjValue = pwdObjValue.trim();
    	pwdObj.value = pwdObjValue;
    }
    
    var pwdColObj = document.getElementById(tdId);
    var pwddescObj = document.getElementById(spanId);
    
    var pwdChkRs = chkPwd(pwdObjValue);
    if(!pwdChkRs.result) {
    	pwdColObj.className = "labbg_err";
    	pwddescObj.style.display = "block";
    	pwddescObj.innerHTML = pwdChkRs['info'];
    	
    	return false;
    }
    
    return true;
}

function equalscheck(firInputId, secInputId, firName, secName, tdId, spanId) {
	var firInputIdObj = document.getElementById(firInputId);
	var secInputIdObj = document.getElementById(secInputId);
	var tdIdObj = document.getElementById(tdId);
	var spanIdObj = document.getElementById(spanId);
	
	var firValue = firInputIdObj.value;
	var secValue = secInputIdObj.value;
	if(firValue == secValue) {
		tdIdObj.className = "labbg_err";
		spanIdObj.style.display = "block";
		spanIdObj.innerHTML = secName + "与" + firName + "输入不能相同";
		return false;
	}
	
	return true;
}

function equalscheck2(firInputId, secInputId, tdId, spanId) {
	var firInputIdObj = document.getElementById(firInputId);
	var secInputIdObj = document.getElementById(secInputId);
	var tdIdObj = document.getElementById(tdId);
	var spanIdObj = document.getElementById(spanId);
	
	var firValue = firInputIdObj.value;
	var secValue = secInputIdObj.value;
	if(firValue != secValue) {
		tdIdObj.className = "labbg_err";
		spanIdObj.style.display = "block";
		spanIdObj.innerHTML = "两次输入的密码不一致，请重新输入";
		return false;
	}
	
	return true;
}